// 主界面
;
define(function(require, exports, module) {
	'use strict';
	var util = require("util");
	var base = require("base");
	var leftMenu = require("../leftMenu/leftMenu");
	var topMenu = require("../topMenu/topMenu");
	var router = require("../hash/pageRouter");
	var dialog = require("dialog");
	var validate = require("validate");
	var databind = require("databind");
	var css_financingDetailInfo = require("../financing/financingDetailInfo.css");
	var css_deliveryNotice = require("./deliveryNotice.css");
	var css_supervisionRelieve = require("./supervisionRelieve.css");
	var js_platform_main = require("./platform_main.js");
	var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
	var imgSrc;
	var left;
	var deliveryId;
	var init = function(page) {
		leftMenu.init(6);
		deliveryId = page.params.deliveryId || base.getUrlParam("deliveryId");
		left = page.params.left || base.getUrlParam("left");
		js_platform_main.init(0);
		inquireDeliveryDetail();
		initEvent();
		router.init();
		$(".left").removeClass("none");
		$("#leftMenu7").find(".leftMenu-item").removeClass("leftMenu-active");
		$("#leftMenu7 .leftMenu li:first-child").addClass("leftMenu-open");
		$("#leftMenu7").find(".leftMenu-item").eq(left).addClass("leftMenu-active");
	};
	var initEvent = function() {
		//若未登录，则返回登陆页面
		if (base.getData("sid") == null || base.getData("sid") == "" || base.getData("sid") == undefined) {
			top.location.href = "../login/login.html";
		}
		//点击首页
		$(".platform_main").unbind("click").click(function() {
			top.location.href = "../main/platform_main.html";
		});

		//点击解除监管列表
		$(".supervisionRelieveList").unbind("click").click(function() {
			router.route("main/supervisionRelieveList.html?left=9", true);
		});
		//点击解除监管
		$(".platformBtns").on("click", ".button-supervisionRelieve", function() {
			dialog.showConfirmDialog("解除监管", "确定要解除此配送任务监管吗", function() {
				createSupervisionRelieve();
			});
		});
	};

	//解除监管通知
	var createSupervisionRelieve = function() {
		base.fnAjax({
			action: "createSupervisionRelieve.json",
			oData: {
				deliveryId: deliveryId
			}, //传递参数
			fnSuccess: function(data) {
				if (data.status == 200) {
					base.alert(1, "解除监管通知成功");
					router.route("main/supervisionRelieveList.html?left=10", true);
				} else {
					base.alert(2, "信息获取失败");
				}
			}
		});
	}

	//获取放货配送明细(配送信息)
	var inquireDeliveryDetail = function() {
			base.fnAjax({
				action: "inquireDeliveryDetail.json",
				async: false,
				oData: {
					deliveryId: deliveryId
				}, //传递参数
				fnSuccess: function(data) {
					if (data.status == 200) {
						var html;
						var pickupDetail = $("#pickupDetail").html();
						if (pickupDetail != undefined) {
							html = juicer(pickupDetail, data);
						}
						$(".tab1").html(html);
						$(".platformBtns").append('<input type="button" class="button-supervisionRelieve button-submit-undefined float-right " value="解除监管" />');
						$(".supervisionRelieve").unbind("click").click(function() {
							var inventoryId = [];
							var $this = $(this).parents("tr.tr_style");
							inventoryId.push($this.attr("inventoryId"));
							showSupervisionRelieve(inventoryId);
						});
					} else {
						base.alert(2, "信息获取失败");
					}
				}
			});
		}
		//显示解除监管弹出框
	var showSupervisionRelieve = function(inventoryId) {
		dialog.showDialog($("#supervisionRelieve_dialog"));
		databind.fillForm($(".supervisionRelieveContent"), {
			inventoryId: inventoryId
		});
		$("#sure_yes_supervisionRelieve").unbind("click").click(function() {

			databind.submitDom($(".supervisionRelieveContent"), function() {
				base.alert(1, "解除监管成功");
				router.route("main/supervisionRelieve.html?deliveryId=" + deliveryId + "&left=" + left, true);
			});
		});
	};
	return {
		init: init
	};
});